package com.aop.xml;

import java.util.Arrays;
import java.util.List;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

public final class LoggingAspect {

	public void ComputerImplAddMethod() {}
	

	 public void beforemethod(JoinPoint joinPoint) {
	 String methodName = joinPoint.getSignature().getName();
	 List<Object> args = Arrays.asList(joinPoint.getArgs());
	 System.out.println("this method >" + methodName + " begins with >" + args);
	 System.out.println("LoggingAspect.beforemethod()");
	 }
	
	 public void afterMethod(JoinPoint joinPoint) {
	 String methodName = joinPoint.getSignature().getName();
	 List<Object> args = Arrays.asList(joinPoint.getArgs());
	 System.out.println("this method >" + methodName + " begins with >" + args);
	 }
	
	 public void afterReturningMethod(JoinPoint joinPoint, Object result) {
	 String methodName = joinPoint.getSignature().getName();
	 List<Object> args = Arrays.asList(joinPoint.getArgs());
	 System.out.println("this method >" + methodName + " begins with >" + args);
	 System.out.println("结果为:" + result);
	 }
	
	 public void AfterThrowingMethod(JoinPoint joinPoint, Exception ex) {
	 String methodName = joinPoint.getSignature().getName();
	 List<Object> args = Arrays.asList(joinPoint.getArgs());
	 System.out.println("this method >" + methodName + " begins with >" + args);
	 System.out.println("结果为:" + ex);
	 }

	public Object AroundMethod(ProceedingJoinPoint pjp) {
		Object proceed = null;
		System.out.println("LoggingAspect.AroundMethod()");
		String methodName = pjp.getSignature().getName();
		Object[] args = pjp.getArgs();
		try {
			proceed = pjp.proceed();
		} catch (Throwable e) {
		}
		return proceed;
	}
}
